package com.qf.config;

import javassist.bytecode.SignatureAttribute;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * @Description: 公用常量
 * @Data: 2022/9/15 14:42
 * @Pacakge: com.qf.config
 * @ClassName: LogAop
 * @Author: fan
 * 日志配置类
 */
@Aspect
@Component
public class LogAop {
    //声明日志对象
    private static final Logger logger = (Logger) LoggerFactory.getLogger(LogAop.class);


    //切点
    @Pointcut(value = "execution(* *.*.*.impl.*.*(..))")
    public void myPointcut(){

    }
    //环绕通知
    @Around("myPointcut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint){
        logger.debug("=====开始执行=====");
        MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
        logger.debug("执行的方法是:"+methodSignature);
        Object proceed = null;
        try {
            proceed = proceedingJoinPoint.proceed();
            logger.debug("=====方法执行结束=====");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            logger.error("方法出现异常{}"+throwable.getMessage());
        }finally{
            logger.debug("====方法执行完成=====");
        }
        return proceed;
    }

}
